home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks '96 / 3D No 'doz / Source / %main.cp next >
Encoding:
Text File  |  1996-06-22  |  2.8 KB  |  169 lines  |  [TEXT/SPM ]

  1. #include <Traps.h>
  2. #include "SAGlobals.h"
  3. #include "Drawing.h"
  4. #include "PPCXfer.h"
  5. #include <Gestalt.h>
  6.  
  7. QDGlobals    qd;
  8.  
  9. typedef pascal void (*DrawPictPP)(PicHandle, Rect*);
  10. typedef pascal Handle (*GetPictPP)(short);
  11. typedef pascal void (*InitWindPP)(void);
  12. typedef pascal void (*InitPPC_PP)(PPCXfer*);
  13.  
  14. GetPictPP        oldGetPicture;
  15. DrawPictPP        oldDrawPicture;
  16. InitWindPP        oldInitWindows;
  17. Ptr                oldLaunch;
  18. Boolean        doCleanup;
  19. Boolean        bypass;
  20. Boolean        isRunning;
  21.  
  22. extern "C" {
  23. pascal Handle MyGetPicture(short);
  24. pascal void MyDrawPicture(PicHandle, Rect*);
  25. pascal void MyInitWindows(void);
  26. //extern void MyLaunch(void);
  27. }
  28.  
  29. pascal void SETGLOB(void);
  30. pascal void RESETGLOB(void);
  31.  
  32. Str31        extFileName;
  33. short        extVRefNum;
  34. long        extDirID;
  35.  
  36. extern "C" void main(void)
  37. {
  38.     Handle        me;
  39.     PPCXfer        ppcx;
  40.     
  41.     if (InitA5())
  42.     {
  43.         SETGLOB();
  44.         
  45.         doCleanup = false;
  46.         bypass = false;
  47.         isRunning = false;
  48.         
  49.         {
  50.             FCBPBRec    pb;
  51.             
  52.             pb.ioFCBIndx = 0;
  53.             pb.ioVRefNum = 0;
  54.             pb.ioRefNum = CurResFile();
  55.             pb.ioNamePtr = extFileName;
  56.             PBGetFCBInfoSync(&pb);
  57.             
  58.             extVRefNum = pb.ioFCBVRefNum;
  59.             extDirID = pb.ioFCBParID;
  60.         }
  61.         
  62.         oldGetPicture = (GetPictPP) GetToolTrapAddress(_GetPicture);
  63.         SetToolTrapAddress((UniversalProcPtr) MyGetPicture, _GetPicture);
  64.         
  65.         RESETGLOB();
  66.     }
  67. }
  68.  
  69. pascal Handle MyGetPicture(short id)
  70. {
  71.     GetPictPP    gp;
  72.     
  73.     SETGLOB();
  74.     gp = oldGetPicture;
  75.     
  76.     if (!bypass && !isRunning)
  77.     {
  78.         short    cResFile = CurResFile();
  79.         short    myFile;
  80.         
  81.         myFile = HOpenResFile(extVRefNum, extDirID, extFileName, fsCurPerm);
  82.         UseResFile(myFile);
  83.         if (InitDraw(id))
  84.             bypass = true;
  85.         CloseResFile(myFile);
  86.         UseResFile(cResFile);
  87.         
  88.         if (!bypass)
  89.         {
  90.             oldDrawPicture = (DrawPictPP) GetToolTrapAddress(_DrawPicture);
  91.             SetToolTrapAddress((UniversalProcPtr) MyDrawPicture, _DrawPicture);
  92.             oldInitWindows = (InitWindPP) GetToolTrapAddress(_InitWindows);
  93.             SetToolTrapAddress((UniversalProcPtr) MyInitWindows, _InitWindows);
  94. //            oldLaunch = (Ptr) GetToolTrapAddress(_Launch);
  95. //            SetToolTrapAddress((UniversalProcPtr) MyLaunch, _Launch);
  96.         }
  97.     }
  98.     RESETGLOB();
  99.     
  100.     return (*gp)(id);
  101. }
  102.  
  103. pascal void MyDrawPicture(PicHandle pic, Rect* r)
  104. {
  105.     DrawPictPP    dp;
  106.     
  107.     SETGLOB();
  108.     dp = (DrawPictPP) oldDrawPicture;
  109.     RESETGLOB();
  110.  
  111.     (*dp)(pic, r);
  112.     
  113.     SETGLOB();
  114.     if (!bypass && !isRunning)
  115.     {
  116.         GDHandle    mainDev;
  117.         
  118.         mainDev = GetMainDevice();
  119.         
  120.         StartDraw(r, (**mainDev).gdPMap);
  121.         
  122.         isRunning = true;
  123.     }
  124.     RESETGLOB();
  125. }
  126.  
  127. pascal void MyInitWindows(void)
  128. {
  129.     InitWindPP    iw;
  130.     
  131.     SETGLOB();
  132.     iw = (InitWindPP) oldInitWindows;
  133.     
  134.     if (!bypass && doCleanup)
  135.     {
  136.         StopDraw();
  137.         DoneDraw();
  138.         
  139.         bypass = true;
  140.     }
  141.     RESETGLOB();
  142.     
  143.     (*iw)();
  144. }
  145.  
  146. static long* __GetCounter(void)
  147. {
  148.     return (long*) "\0\0\0";
  149. }
  150.  
  151. pascal void SETGLOB(void)
  152. {
  153.     long*    lp = __GetCounter();
  154.     
  155.     if (*lp == 0)
  156.         SetUpA5();
  157.     
  158.     ++(*lp);    
  159. }
  160.  
  161. pascal void RESETGLOB(void)
  162. {
  163.     long*    lp = __GetCounter();
  164.     
  165.     --(*lp);
  166.     
  167.     if (*lp == 0)
  168.         RestoreA5();
  169. }